home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / New System Software Extensions / QuickDraw™ GX 1.1.2 / Programming Stuff / Sample Code / Printing Samples / Printer Drivers… / CustomWriter GX 1.0.3 ƒ / ChooserSupport.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-20  |  5.7 KB  |  229 lines  |  [TEXT/MPS ]

  1. /*
  2.     FILENAME
  3.         ChooserSupport.c
  4.  
  5.     DESCRIPTION
  6.         Contains code for PACK and LDEF resources used by the Chooser.
  7.  
  8.     COPYRIGHT
  9.         Copyright © 1995 Apple Computer, Inc.
  10.         All rights reserved.
  11.     
  12.     Modification history
  13.         06/14/95 - Dave Hersey -    Version 1.0.3 to fix a bug in
  14.                                     CustomBufferingAndIO.c when creating
  15.                                     high-res PICTs, and to make the size
  16.                                     of buffers more flexible.
  17.  
  18.         05/26/95 - Dave Hersey -    Version 1.0.2 to add the new 'outp'
  19.                                     desktop printer resource in NewApp.c.
  20.  
  21.         05/03/95 - Dave Hersey -    Version 1.0.1 to fix some minor bugs in
  22.                                     CustomBufferingAndIO.c.
  23.  
  24.         01/14/95 - Dave Hersey -    Created from the shell of a hollowed-out
  25.                                     ImageWriter driver.
  26.  
  27.     NOTE: Relevant goodies are listed in MPW's "Mark" menu.
  28.  
  29. */
  30.  
  31. #include "CommonDefines.h"
  32.  
  33.  
  34. /*    -----------------------------------------------------------------------
  35.  
  36.     Device is the standard Chooser "Device" routine that all QuickDraw GX
  37.     drivers require.
  38.  
  39.     -----------------------------------------------------------------------    */
  40.  
  41. pascal OSErr Device(short message, short caller, StringPtr objName, 
  42.                     StringPtr zoneName, ListHandle theList, long p2)
  43. {
  44.     
  45.     OSErr            anErr = noErr;
  46.     extern Str31     gDriverName;
  47.     StringPtr        pDriverName = (StringPtr) &gDriverName;
  48.     extern gxJob    gJob;
  49.     gxJob            *pJob = &gJob;
  50.     
  51.     // start up GX.
  52.  
  53.     if (message == initializeMsg)
  54.     {
  55.         FCBPBRec    pb;
  56.  
  57.         // determine the driver name
  58.         pb.ioCompletion     = nil;
  59.         pb.ioNamePtr         = pDriverName;
  60.         pb.ioVRefNum         = 0;
  61.         pb.ioRefNum         = CurResFile();
  62.         pb.ioFCBIndx         = 0;
  63.         anErr = PBGetFCBInfo(&pb, false);
  64.  
  65.         *pJob = nil;
  66.         if (anErr == noErr)
  67.         {
  68.             GXEnterGraphics();
  69.             anErr = GXGetGraphicsError(nil);
  70.             if (anErr == noErr)
  71.             {
  72.                 anErr = GXInitPrinting();
  73.                 if (anErr != noErr)
  74.                     GXExitGraphics();
  75.             }
  76.         }
  77.     }
  78.         
  79.     // Let the system handle the choosing for us.
  80.  
  81.     if (anErr == noErr)
  82.     {
  83.         if ((*pJob != nil) || (message == initializeMsg))
  84.         {
  85.             anErr = GXHandleChooserMessage(pJob, pDriverName, message, caller, objName, zoneName, theList, p2);
  86.         
  87.             // Tear down GX when done.
  88.  
  89.             if ((message == terminateMsg) && (p2 == terminateMsg))
  90.             {
  91.                 GXExitPrinting();
  92.                 GXExitGraphics();
  93.             }
  94.         }
  95.     }
  96.         
  97.     return anErr;
  98. }
  99.  
  100.  
  101. /*    -----------------------------------------------------------------------
  102.     LDEF is our driver's Chooser LDEF.
  103.  
  104.     This is an LDEF that simply plots an icon, and lets the user "Create."
  105.  
  106.     -----------------------------------------------------------------------    */
  107.  
  108. pascal void LDEF(
  109.     short         message,        // What operation to perform on list
  110.     Boolean     select,            // Is this cell to be selected or not?
  111.     Rect        *theRect,        // Rectangle of this cell, clipped to window
  112.     Cell        theCell,        // Which cell this is
  113.     short        dataOffset,        // Offset into data for this cell
  114.     short        dataLen,        // Length of data for this cell
  115.     ListHandle    theList)        // The list to act upon
  116.     {
  117.         Handle        cicnHdl;
  118.         Rect        iconRect;
  119.         char        userPrompt[] = "\pPrint to Disk";
  120.  
  121. #pragma unused(theCell, dataOffset, dataLen);
  122.  
  123.         switch (message)
  124.         {
  125.             case lInitMsg:
  126.                 {
  127.                     Cell    aCell = {0, 1};
  128.                     (*theList)->userHandle = (Handle) GetCIcon(r_ChooserIcon);
  129.     
  130.                     if ((*theList)->userHandle)
  131.                     {
  132.                         DetachResource((*theList)->userHandle);
  133.                         LSetCell((Ptr) &userPrompt[1], userPrompt[0], aCell, theList);
  134.                         LSetSelect(true, aCell,theList);
  135.                     }
  136.                 }
  137.                 break;
  138.                 
  139.             case lCloseMsg:
  140.                 if ((*theList)->userHandle)
  141.                 {
  142.                     DisposeCIcon((CIconHandle) (*theList)->userHandle);
  143.                     (*theList)->userHandle = nil;
  144.                 }
  145.                 break;
  146.  
  147.             case lHiliteMsg:
  148.             case lDrawMsg:
  149.                 cicnHdl = (*theList)->userHandle;
  150.                 if (cicnHdl == nil) break;
  151.                 
  152.                 // draw the cell as an icon
  153.                 // center the icon rect on the list with a top margin of 10 pixels
  154.  
  155.                 iconRect.top = theRect->top + 10;
  156.                 iconRect.left = theRect->left + ((theRect->right - theRect->left) >> 1) - 16;
  157.                 iconRect.bottom = iconRect.top + 32;
  158.                 iconRect.right = iconRect.left + 32;
  159.                     
  160.                     
  161.                 // draw the icon
  162.  
  163.                 if (cicnHdl != nil)
  164.                     PlotCIcon(&iconRect, (CIconHandle) cicnHdl);
  165.                                 
  166.                 // Get the general area under the icon in which to draw the label
  167.  
  168.                 iconRect.left = theRect->left + 2;
  169.                 iconRect.right = iconRect.left + (**theList).cellSize.h - 2;
  170.                 iconRect.top = iconRect.bottom + 2;
  171.                 iconRect.bottom = theRect->bottom;
  172.         
  173.                 // use a nice small font for the label            
  174.  
  175.                 TextFont(applFont);
  176.                 TextSize(9);
  177.                     
  178.                 {
  179.                     short            labelWidth;
  180.                     short            rectWidth;
  181.                     short            labelHeight;
  182.                     FontInfo        theInfo;
  183.                     unsigned char    theHilightMode;
  184.                     
  185.     /*    Get rid of any previous label, compute the height of the new label,
  186.         compute where to draw the text, truncate the string to fit within the box,
  187.         compute the new width of the string, center the string, and draw it.
  188.     */
  189.                     EraseRect(&iconRect);
  190.                     iconRect.top += 2;
  191.                         
  192.                     GetFontInfo(&theInfo);
  193.                     labelHeight = theInfo.ascent +theInfo.leading;
  194.                 
  195.                     iconRect.bottom = iconRect.top + labelHeight;
  196.                     rectWidth = iconRect.right-iconRect.left;
  197.                     
  198.     // Not very localizable...  Use resources in the real world.
  199.  
  200.                     TruncString(rectWidth, (unsigned char *) userPrompt, smTruncEnd);
  201.                     labelWidth = StringWidth((unsigned char const *) userPrompt);
  202.                 
  203.                     iconRect.left += (rectWidth >> 1) - (labelWidth >> 1);
  204.                     MoveTo(iconRect.left, iconRect.bottom);
  205.                     DrawString((unsigned char const *) userPrompt);
  206.  
  207.     // If selecting the icon, highlight the text.
  208.  
  209.                     if (select)
  210.                     {
  211.                         iconRect.right = iconRect.left + labelWidth;
  212.                         iconRect.bottom += theInfo.descent;
  213.                         
  214.                         InsetRect(&iconRect, -1, -1);
  215.                         
  216.                         theHilightMode = LMGetHiliteMode();
  217.                         BitClr(&theHilightMode, pHiliteBit);
  218.                         LMSetHiliteMode(theHilightMode);
  219.                         InvertRect(&iconRect);
  220.                     }
  221.  
  222.                     TextFont(applFont);
  223.                     TextSize(0);
  224.                 }
  225.                 break;
  226.         }
  227. }
  228.  
  229.